package cn.com.taurus.controller.user;

import cn.com.taurus.bean.*;
import cn.com.taurus.biz.*;
import cn.com.taurus.controller.major.FundWebController;
import cn.com.taurus.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author zhy
 * @createTime 2021-7-6 00:23:56
 * @remark 我的钱包控制层
 * @version 1.0
 */
@Controller
public class MyPurseController {

    @Autowired
    MyPurseWebBeanBiz myPurseWebBeanBiz;
    @Autowired
    HomePageWebBeanBiz homePageWebBeanBiz;
    @Autowired
    LoginRegisterController loginRegisterController;
    @Autowired
    ClientOptionalBiz clientOptionalBiz;
    @Autowired
    DealMessageBiz dealMessageBiz;
    @Autowired
    ClientAccountBiz clientAccountBiz;
    @Autowired
    DealRecordBiz dealRecordBiz;
    @Autowired
    FundBiz fundBiz;
    @Autowired
    FundHoldBiz fundHoldBiz;
    @Autowired
    RedeemMessageBiz redeemMessageBiz;
    @Autowired
    BankMessageBiz messageBiz;
    @Autowired
    ClientAccountBiz accountBiz;
    @Autowired
    BankBiz bankBiz;

    @Autowired
    MyPurseController myPurseController;
    @Autowired
    FundWebController fundWebController;
    @Autowired
    RedeemRecordBiz redeemRecordBiz;


    ModelAndView modelAndView = new ModelAndView();

    @Autowired
    ClientBiz clientBiz;

    private Double buyMoney;
    private ClientAccount clientAccount;
    private RedeemMessage redeemMessage;
    private String fhId;
    private Double dwjz;
    //设置转跳页面计数变量count
    private Integer count=0;
    Double overAllAsset;
    Integer caId;
    double luckCapoint;
    Integer cid;
    double LuckMoneyBox;
    String name;

    private MyPurseWebBean myPurseWebBean;
    public MyPurseWebBean getMyPurseWebBean() {
        return myPurseWebBean;
    }
    public void setMyPurseWebBean(MyPurseWebBean myPurseWebBean) {
        this.myPurseWebBean = myPurseWebBean;
    }

    @RequestMapping(value = "/Anonymous/myPurseWeb")
    public ModelAndView myPurseWeb(){
        this.myPurseWebBean = myPurseWebBeanBiz.selectMyPurseWebData(loginRegisterController.getClient().cAccount);
        modelAndView.setViewName("user/myPurse");
        if (count == 2){
            //重置count
            count=0;
        }
        cid = myPurseWebBean.getCId();
        name = loginRegisterController.getClient().cAccount;
        luckCapoint = myPurseWebBean.getCaPoint();
        LuckMoneyBox = myPurseWebBean.getMoneyBox();


        //赋值计数变量count
        modelAndView.addObject("count",count);
        //计数变量自增
        modelAndView.addObject("myPurseData",myPurseWebBean);
        modelAndView.addObject("capoint",myPurseWebBean.getCaPoint());
        modelAndView.addObject("moneyBox",myPurseWebBean.getMoneyBox());
        modelAndView.addObject("noMoney","false");
        return modelAndView;
    }

    @RequestMapping(value = "/Anonymous/clientExit")
    public ModelAndView clientExit(){

        List<HomePageWebBean> list = homePageWebBeanBiz.selectRandomFiveFund();
        modelAndView.addObject("homePageData",list);
        //将客户类清空
        loginRegisterController.setClient(null);
        //将myPurseData清空
        modelAndView.addObject("myPurseData",null);
        modelAndView.setViewName("major/homepage");
        //count清0
        count=0;
        return modelAndView;
    }


    @RequestMapping(value = "/Anonymous/optionalFund")
    public ModelAndView optionalFund(){
        //根据基金自选表查询出该用户自选的基金 通过cId cId从loginRegisterController里面拿
        List<Fund> list = clientOptionalBiz.selectClientOptionalFundByCId(loginRegisterController.getClient().getcId());
        modelAndView.addObject("fundData",list);
        modelAndView.addObject("myPurseData",myPurseController.getMyPurseWebBean());
        modelAndView.setViewName("user/optionalFund");
        return modelAndView;
    }

    /**
     * 我的持仓控制层
     * @return
     */
    @RequestMapping(value = "/Anonymous/myPosition")
    public ModelAndView myPosition(){
        //根据loginRegisterController获取客户client对象
        Client client = loginRegisterController.getClient();
        //根据client查询CaId
        Integer caId = clientAccountBiz.selectCaIdByCid(client.getcId());
        modelAndView.addObject("clientData",client);
        //根据myPurseController获取myPurse对象
        modelAndView.addObject("myPurseData",myPurseController.getMyPurseWebBean());
        modelAndView.addObject("fundHoldData",myPurseWebBeanBiz.selectMyFundHoldByCaId(caId));
        for (FundHoldBean fundHoldBean:myPurseWebBeanBiz.selectMyFundHoldByCaId(caId)) {
            System.err.println(fundHoldBean.toString());
        }
        //count自增
        count++;
        //赋值
        modelAndView.addObject("count",count);
        modelAndView.setViewName("user/myPosition");
        return modelAndView;
    }

    /**
     * 申购记录查询控制层
     * @return
     */
    @RequestMapping(value = "/Anonymous/acceptAffirm")
    public ModelAndView acceptAffirm(){
        //根据loginRegisterController获取客户client对象
        Client client = loginRegisterController.getClient();
        //根据client查询CaId
        Integer caId = clientAccountBiz.selectCaIdByCid(client.getcId());
        modelAndView.addObject("clientData",client);
        //根据myPurseController获取myPurse对象
        modelAndView.addObject("myPurseData",myPurseController.getMyPurseWebBean());
        //将caId放入 Model
        modelAndView.addObject("caId",caId);
        //根据caId查询交易申请存入model中
        modelAndView.addObject("dealMessageData",dealMessageBiz.selectDealMessageCaId(caId));
        modelAndView.setViewName("user/acceptAffirm");
        return modelAndView;
    }
    /**
     * 贖回申请查询控制层
     * @return
     */
    @RequestMapping(value = "/Anonymous/redeemAffirm")
    public ModelAndView redeemAffirm(){
        //根据loginRegisterController获取客户client对象
        Client client = loginRegisterController.getClient();
        //根据client查询CaId
        Integer caId = clientAccountBiz.selectCaIdByCid(client.getcId());
        modelAndView.addObject("clientData",client);
        //根据myPurseController获取myPurse对象
        modelAndView.addObject("myPurseData",myPurseController.getMyPurseWebBean());
        //将caId放入 Model
        modelAndView.addObject("caId",caId);
        //根据caId查询交易申请存入model中
        modelAndView.addObject("redeemMessageData",redeemMessageBiz.selectDealMessageCaId(caId));
        modelAndView.setViewName("user/redeemAffirm");
        return modelAndView;
    }
    /**
     * 申购成功查询控制层
     * @return
     */
    @RequestMapping(value = "/Anonymous/acceptWin")
    public ModelAndView acceptWin(Integer caId){
        //根据caid查询dealRecordWebBean的数据
        List<DealRecordWebBean> list = dealRecordBiz.selectDealRecordByCaId(caId);
        modelAndView.addObject("dealRecordData",list);
        System.out.println(list);
        modelAndView.setViewName("user/acceptWin");
        return modelAndView;
    }

    /**
     * 赎回成功查询控制层
     * @return
     */
    @RequestMapping(value = "/Anonymous/redeemWin")
    public ModelAndView redeemWin(Integer caId){
        //根据caid查询dealRecordWebBean的数据
        List<RedeemWebBean> list = redeemMessageBiz.selectRedeemRecordByCaId(caId);
        modelAndView.addObject("redeemRecordData",list);
        modelAndView.setViewName("user/redeemWin");
        return modelAndView;
    }

    /**
     * 确认申购控制层
     * @return
     */
    @RequestMapping(value = "/Anonymous/acceptBuy")
    public ModelAndView acceptBuy(Integer dmId,Integer caId){
        //根据dmId查询单个交易申请
        DealMessage dealMessage = dealMessageBiz.buyApplicationSelectOne(dmId);
        //根据交易申请查询fid查询基金对象
        Fund fund = fundBiz.selectFundByFid(dealMessage.getfId());
        //得到现在的时间
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String dateTime = sdf.format(date.getTime());
        //去除时分秒
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        String dateTime2 = sdf2.format(date.getTime());

        //按照基金今天的净值根据购买金额  - 手续费 计算份额
        Double buyShare = (dealMessage.getApplyBuy() - dealMessage.getServiceCharge()) / fund.getDwjz();
        //将未确认改为已确认
        dealMessage.setShareAgree("已确认");
        dealMessageBiz.buyApplicationUpdate(dealMessage);

        //根据caId查询cId查询clientAccount对象
        ClientAccount clientAccount = clientAccountBiz.selectAllPurse(clientAccountBiz.selectCIdByCaId(caId));
        //根据dealMessage的serviceCharge手续费增加账户积分
        clientAccount.setCaPoint(clientAccount.getCaPoint() + dealMessage.getServiceCharge());
        //修改账户
        clientAccountBiz.clientAccountUpdate(clientAccount);


        //添加交易流水
        dealRecordBiz.buyRecord(new DealRecord(0,dmId,dateTime,buyShare));
        //添加基金持有
        fundHoldBiz.fundHoldAdd(new FundHold(fund.getfId(),caId,buyShare,dateTime,fund.getDwjz(),dateTime2));



        //重新查询一遍
        //根据caId查询交易申请存入model中
        modelAndView.addObject("dealMessageData",dealMessageBiz.selectDealMessageCaId(caId));
        modelAndView.setViewName("user/acceptAffirm");
        return modelAndView;
    }





    /**
     * 确认赎回申购控制层
     * @return
     */
    @RequestMapping(value = "/Anonymous/acceptRedeem")
    public ModelAndView acceptRedeem(Double buyMoney,Integer rmId,Integer caId){
        //根据dmId查询单个交易申请
        RedeemMessage redeemMessage = redeemMessageBiz.redeemApplicationSelectOne(rmId);
        //根据交易申请查询fid查询基金对象
        Fund fund = fundBiz.selectFundByFid(redeemMessage.getfId());
        //得到现在的时间
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dateTime = sdf.format(date.getTime());
        //按照基金今天的净值根据购买金额 - 手续费 计算份额
        Double buyShare = (redeemMessage.getApplyRedeem() - redeemMessage.getServiceCharge()) / fund.getDwjz();

        //将未确认改为已确认
        redeemMessage.setShareAgree("已确认");
        redeemMessageBiz.redeemApplicationUpdate(redeemMessage);
        //查询账户对象
        this.clientAccount = clientAccountBiz.selectAllPurse(clientAccountBiz.selectCIdByCaId(caId));
        System.out.println(caId);

        System.out.println(clientAccount);
        //-------------------计算我的钱包金额----------------------------
        //计算冻结金额  冻结金额 - 赎回金额 + 手续费
        Double frozenMoney = clientAccount.getFrozenMoney() - buyMoney + redeemMessage.getServiceCharge();
        //计算公募基金金额
        Double publicFunds = clientAccount.getPublicFunds()- buyMoney + redeemMessage.getServiceCharge();
        //计算储蓄罐活期余额
        Double moneyBox = clientAccount.getMoneyBox()+buyMoney;

//        clientAccount.setFrozenMoney(frozenMoney); 暂时别管
        clientAccount.setPublicFunds(publicFunds);
        clientAccount.setMoneyBox(moneyBox);

        clientAccountBiz.clientAccountUpdate(clientAccount);
        //--------------------------------------------------------------
        //添加交易流水
        redeemRecordBiz.redeemRecord(new RedeemRecord(0,rmId,dateTime,buyShare));
        //重新查询一遍
        //根据caId查询交易申请存入model中
        modelAndView.addObject("redeemMessageData",redeemMessageBiz.selectDealMessageCaId(caId));
        modelAndView.setViewName("user/redeemAffirm");
        return modelAndView;
    }



    /**
     * 用户新增基金自选
     * @return
     */
    @RequestMapping(value = "/Anonymous/addOptionalFund")
    public ModelAndView addOptionalFund(String fId){

        if (loginRegisterController.getClient() != null){
            Integer cId = loginRegisterController.getClient().getcId();
            //新增自选
            clientOptionalBiz.insertClientOptional(new ClientOptional(clientOptionalBiz.selectCpId(),fId,cId));

            List<Fund> list = clientOptionalBiz.selectClientOptionalFundByCId(cId);
            modelAndView.addObject("fundData",list);

            //跳回去,调用别的控制层
            modelAndView = fundWebController.fundWeb(fId);
        }else {
            //转跳到登录界面
            modelAndView.setViewName("major/fundLogin");
        }
        return modelAndView;
    }

    /**
     * 删除基金自选
     * @return
     */
    @RequestMapping(value = "/Anonymous/deleteOptionalFund")
    public ModelAndView deleteOptionalFund(String fId){
        Integer cId = loginRegisterController.getClient().getcId();

        clientOptionalBiz.deleteClientOptionalByFId(fId,cId);

        List<Fund> list = clientOptionalBiz.selectClientOptionalFundByCId(cId);
        modelAndView.addObject("fundData",list);
        modelAndView.setViewName("user/optionalFund");
        return modelAndView;
    }

    @RequestMapping(value = "/Anonymous/redeem2")
    public ModelAndView userBuy2() {
        modelAndView.setViewName("major/redeem2");
        return modelAndView;
    }

    @RequestMapping(value = "/Anonymous/redeem3")
    public ModelAndView userBuy3() {
        modelAndView.setViewName("major/redeem3");
        return modelAndView;
    }

    @RequestMapping(value = "/Anonymous/redeem")
    public ModelAndView userBuy(String fhId){
        //获取用户信息
        Client client = loginRegisterController.getClient();
        if (client != null){
            modelAndView.addObject("fund",redeemMessageBiz.selectFundFundTypeFundHold(new Integer(fhId)));
            System.out.println(redeemMessageBiz.selectFundFundTypeFundHold(new Integer(fhId)));
            //计算 能赎回的最大金额
            Double num = redeemMessageBiz.selectFundFundTypeFundHold(new Integer(fhId)).
                    getDwjz()*
                    redeemMessageBiz.selectFundFundTypeFundHold(new Integer(fhId))
                            .getShares();
            //保留小数点后两位
            modelAndView.addObject("num",String.format("%.2f",num));
            //计算手续费
            Double num2 = num*redeemMessageBiz.selectFundFundTypeFundHold(new Integer(fhId)).getAfterRate();
            modelAndView.addObject("num2",num2);
            modelAndView.addObject("clientData",loginRegisterController.getClient());
            modelAndView.setViewName("major/redeem");
            return modelAndView;
        }else {
            modelAndView.setViewName("major/fundLogin");
            return modelAndView;
        }
    }

    /**
     * 确认赎回
     * @param cAccount 用户账户
     * @param fId 基金编号
     * @param buyMoney 购买金额
     * @return modelAndView
     */
    @RequestMapping(value = "/Anonymous/redeemBuy")
    public ModelAndView verifyBuy(String cAccount,String fId,String buyMoney,String serviceCharge,String fhId,Double dwjz){
        if (cAccount != null && fId != null && buyMoney != null && serviceCharge != null){
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(serviceCharge);
            //根据账户查询相应cId
            Integer cId = clientBiz.selectCIdBycAccount(cAccount);
            //根据cId查询相应caId
            Integer caId = clientAccountBiz.selectCaIdByCid(cId);
            //生成交易申请订单
            this.redeemMessage = new RedeemMessage(caId,fId,Double.parseDouble(buyMoney)-Double.parseDouble(serviceCharge),simpleDateFormat.format(date.getTime()),Double.parseDouble(serviceCharge),"未确认");
            //将客户账户、购买金额对象放入全局
            clientAccount = clientAccountBiz.selectAllPurse(cId);
            this.buyMoney=Double.parseDouble(buyMoney);
            this.fhId=fhId;
            this.dwjz=dwjz;
            //添加对象
            modelAndView.addObject("cAccount",cAccount);
            modelAndView.addObject("fName",fundBiz.selectFundByFid(fId).getfName());
            modelAndView.addObject("redeemMessageData",redeemMessage);

            //切换到确认购买界面
            modelAndView.setViewName("major/redeem2");
            return modelAndView;
        }else{
            //回到购买界面
            modelAndView.setViewName("major/redeem");
            return modelAndView;
        }
    }

    /**
     * 判断交易密码
     * ajax要返回json
     * @param buyPassword
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/Anonymous/redeemPossible")
    public String possible(String buyPassword){
        Client client = loginRegisterController.getClient();
        //查询出用户相应的账户密码
        Integer buyPasswordData = clientAccountBiz.selectBuyPasswordByCId(client.cId);
        System.err.println(buyPassword+" "+buyPasswordData);
        if (Integer.parseInt(buyPassword) == buyPasswordData){
            return "{\"url\":\"/Anonymous/redeemResult\"}";
        }else {
            return "{\"url\":\"/Anonymous/redeem2\"}";
        }
    }

    /**
     * 赎回申请结果
     * @return
     */
    @RequestMapping(value = "/Anonymous/redeemResult")
    public ModelAndView buyResult() {
        if (clientAccount.getMoneyBox() - buyMoney < 0){
            //赎回申请失败，储蓄罐金额不足
            modelAndView.setViewName("major/redeem3");

        }else {
            //交易申请对象
            modelAndView.addObject("redeemMessageData",redeemMessage);
            //根据交易申请表的fId获取fName
            String fName = fundBiz.selectFundByFid(redeemMessage.getfId()).getfName();
            modelAndView.addObject("fName",fName);
            //根据loginRegisterController里的client获取cAccount
            String cAccount = loginRegisterController.getClient().getcAccount();
            modelAndView.addObject("cAccount",cAccount);

            Double num = (buyMoney - redeemMessage.getServiceCharge() ) / dwjz;
            fundHoldBiz.updateFundHold(new FundHold(num,new Integer(fhId)));

            //插入交易申请
            redeemMessageBiz.redeemApplication(redeemMessage);
            //购买成功，储蓄罐金额足
            modelAndView.setViewName("major/redeem4");
        }
        return modelAndView;
    }


    /**
     * 给用户计算收益，然后改变我的钱包数据
     * @return
     */
    @RequestMapping(value = "/Anonymous/countEarnings")
    public ModelAndView countEarnings(@RequestParam(value = "fhIdArr[]")Integer[] fhIdArr, Double dayMoney, Double resultMoney) {
        //获取到用户账户
        clientAccount = clientAccountBiz.selectAllPurse(loginRegisterController.getClient().cId);
        //修改账户收益
        clientAccount.setCaTodayEarnings(dayMoney);
        clientAccount.setCaResultEarnings(resultMoney);

        System.err.println("总收益："+resultMoney+"日收益："+dayMoney);
        //修改公募基金907.86  648.27 注意加的是日收益，不是总收益 不然会加多
        clientAccount.setPublicFunds(clientAccount.getPublicFunds() + dayMoney);
        //修改总资产
        clientAccount.setOverAllAsset(clientAccount.getOverAllAsset() + dayMoney);

        //修改数据更新时间
        for (int i = 0; i < fhIdArr.length; i++) {
            fundHoldBiz.updateDataUpdateTimeByFhId(fhIdArr[i]);
        }

        //修改客户账户
        clientAccountBiz.clientAccountUpdate(clientAccount);

        return modelAndView;
    }



    /**
     * 查看账户银行卡信息
     * @return
     */

    @RequestMapping(value = "/Anonymous/selectBankMessage")
    public ModelAndView selectBankMessage(BankMessageBean bankMessageBean, HttpServletRequest request){
        Integer cId = loginRegisterController.getClient().getcId();
        caId =accountBiz.selectCaIdByCid(cId);
        //根据caId查询出账户总资产
        overAllAsset=  accountBiz.selectOverAllAssetByCaId(caId);
        //根据caId查询名下银行卡信息
        List<BankMessageBean> messageList = messageBiz.selectBankMessage(new BankMessageBean(caId));
        modelAndView.addObject("messageList",messageList);
        modelAndView.setViewName("user/charge");
        return modelAndView;
    }


    @RequestMapping("/Anonymous/luck.asd")
    public ModelAndView lucks(String data,HttpServletRequest request){
        System.out.println("进入计算抽奖结果");
        ClientAccount clientAccount = clientAccountBiz.selectAllPurse(cid);

        double pay=LuckMoneyBox+Double.valueOf(data);
        Double resultMoney = clientAccount.getOverAllAsset()+Double.valueOf(data);
        double skew=luckCapoint-1000;
        System.out.println(LuckMoneyBox);
        System.out.println(luckCapoint);
        this.myPurseWebBean = myPurseWebBeanBiz.selectMyPurseWebData(name);
        myPurseWebBeanBiz.updateLuck(new MyPurseWebBean(cid,skew,pay,resultMoney));
        System.out.println(myPurseWebBean.toString());
        modelAndView.addObject("myPurseData",myPurseWebBean);
        modelAndView.setViewName("user/myPurse");
        return modelAndView;
    }

    @RequestMapping(value = "/Anonymous/luck.go")
    public ModelAndView gotoLuck(){
        modelAndView.setViewName("major/luck");
        System.out.println("进入幸运大抽奖");
        return modelAndView;
    }



    /**
     * 充钱
     * @param bankMessageBean
     * @param request
     * @return
     */
    @RequestMapping(value = "/Anonymous/chargeMoney")
    public ModelAndView chargeMoney(BankMessageBean bankMessageBean, HttpServletRequest request){
        //获取输入的最新资产
        Double newMoney =Double.parseDouble(request.getParameter("newMoney"));

        //修改账户总资产，为最新资产
        ClientAccount clientAccount = accountBiz.selectAllPurse(accountBiz.selectCIdByCaId(caId));

        //最新资产等于 原资金加充值资金
        Double chargeMoney =newMoney+clientAccount.getOverAllAsset();

        //储蓄罐活期 增加
        Double boxMoney =newMoney+clientAccount.getMoneyBox();

        clientAccount.setOverAllAsset(chargeMoney);
        clientAccount.setMoneyBox(boxMoney);

        accountBiz.clientAccountUpdate(clientAccount);

        this.myPurseWebBean = myPurseWebBeanBiz.selectMyPurseWebData(loginRegisterController.getClient().cAccount);
        modelAndView.setViewName("user/myPurse");
        modelAndView.addObject("noMoney","false");
        modelAndView.addObject("myPurseData",myPurseWebBean);
        return modelAndView;
    }
    /**
     * 添加银行卡
     * @return
     */
    @RequestMapping(value = "/Anonymous/addBank")
    public ModelAndView addBank(BankMessageBean bankMessageBean, HttpServletRequest request){
        modelAndView.setViewName("user/addBank");
        return modelAndView;
    }

    /**
     * 完成添加银行卡
     * @return
     */
    @RequestMapping(value = "/Anonymous/finishAddBank")
    public ModelAndView finishAddBank(BankMessageBean bankMessageBean,String bankName , HttpServletRequest request){
        //bankCode
        String bankCode =request.getParameter("bankCode");
        System.out.println(bankCode+"bankcode");

        //cId
        Integer cId = loginRegisterController.getClient().getcId();
        System.out.println(cId+"cid");
        //caId
        caId =accountBiz.selectCaIdByCid(cId);
        System.out.println(caId+"caid");
        //根据caId查询名下银行卡信息
        List<BankMessageBean> messageList = messageBiz.selectBankMessage(new BankMessageBean(caId));
        System.out.println(messageList+"lsit");
        //bId
        BankMessageBean bean= messageList.get(0);
        Integer bId =bean.getbId();
        System.out.println(bId+"bid");
        if (bankBiz.selectBankCode(bId)==null){//
            bankBiz.insertBank(bankCode,bankName,bId);
        }else {
            ClientAccountBankBean clientAccountBankBean =new ClientAccountBankBean();
            clientAccountBankBean.setBankCode(bankCode);
            //bankType =bankName
            clientAccountBankBean.setBankType(bankName);
            bankBiz.insertBankSecond(clientAccountBankBean);
            System.out.println(clientAccountBankBean.getbId());
            bankBiz.insertClientAccountAndBank(new ClientAccountBankBean(caId, clientAccountBankBean.getbId()));
        }
        List<BankMessageBean> messageList2 = messageBiz.selectBankMessage(new BankMessageBean(caId));
        modelAndView.addObject("messageList",messageList2);
        modelAndView.setViewName("user/charge");
        return modelAndView;
    }


    /**
     * 银行卡提现跳转
     * @return
     */

    @RequestMapping(value = "/Anonymous/takeMoney")
    public ModelAndView takeMoney(BankMessageBean bankMessageBean, HttpServletRequest request){
        Integer cId = loginRegisterController.getClient().getcId();
        caId =accountBiz.selectCaIdByCid(cId);
        //根据caId查询出账户总资产
        overAllAsset=  accountBiz.selectOverAllAssetByCaId(caId);
        //根据caId查询名下银行卡信息
        List<BankMessageBean> messageList = messageBiz.selectBankMessage(new BankMessageBean(caId));
        modelAndView.addObject("messageList",messageList);
        modelAndView.setViewName("user/takeMoney");

        return modelAndView;
    }

    /**
     *  银行卡提现
     * @param bankMessageBean
     * @param request
     * @return
     */
    @RequestMapping(value = "/Anonymous/finishTakeMoney")
    public ModelAndView finishTakeMoney(BankMessageBean bankMessageBean, HttpServletRequest request){
        //cId
        Integer cId = loginRegisterController.getClient().getcId();
        //获取提现金额
        Double takeMoney =Double.parseDouble(request.getParameter("takeMoney"));
        System.out.println(takeMoney);
        ClientAccount clientAccount =accountBiz.selectAllPurse(cId);
        System.out.println(accountBiz.selectAllPurse(cId));
        Double MoneyBox =clientAccount.getMoneyBox();
        Double overAllAssets=clientAccount.getOverAllAsset();
        if (MoneyBox>=takeMoney && overAllAssets>=takeMoney){
            clientAccount.setOverAllAsset(overAllAssets-takeMoney);
            clientAccount.setMoneyBox(MoneyBox-takeMoney);
            accountBiz.clientAccountUpdate(clientAccount);
            modelAndView.addObject("noMoney","false");
        }
        else {
            modelAndView.addObject("noMoney","true");
        }
        this.myPurseWebBean = myPurseWebBeanBiz.selectMyPurseWebData(loginRegisterController.getClient().cAccount);

        modelAndView.addObject("myPurseData",myPurseWebBean);
        modelAndView.setViewName("user/myPurse");
        return modelAndView;
    }
}
